#ifndef __MULTISPRITE_H
#define __MULTISPRITE_H

#include "gamedata.h"
#include "sprite.h"
#include "multiSpriteFactory.h"

class MultiSprite : public Sprite
{
	public:
		MultiSprite( const string& name ) : 
			Sprite( name, MultiSpriteFrameFactory::getInstance() ),
			currentFrame(0),
			numberOfFrames( Gamedata::getInstance().getXmlInt(name+"FramesCol") ),
			frameInterval(Gamedata::getInstance().getXmlInt(name+"FrameInterval")),
			frameWidth( frame->getWidth() ), frameHeight( frame->getWidth() ),
			worldWidth( Gamedata::getInstance().getXmlInt("worldWidth") ),
			worldHeight( Gamedata::getInstance().getXmlInt("worldHeight") ),
			offset(0)
		{ }

		MultiSprite(const Vector2f& pos, const Vector2f& vel, const Frame* fm, const string& name) : 
			Sprite(pos, vel, name, fm),
			currentFrame(0),
			numberOfFrames( Gamedata::getInstance().getXmlInt(name+"FramesCol") ),
			frameInterval(Gamedata::getInstance().getXmlInt(name+"FrameInterval")),
			frameWidth( fm->getWidth() ), frameHeight( fm->getWidth() ),
			worldWidth( Gamedata::getInstance().getXmlInt("worldWidth") ),
			worldHeight( Gamedata::getInstance().getXmlInt("worldHeight") ),
			offset(0)
		{}

		virtual const Frame* getFrame() const { return &frame[currentFrame]; }
		void draw() const { frame[currentFrame].draw(X(), Y()); }
		virtual void update(Uint32 ticks);
		void handleMouseMotion();

	private:
		unsigned currentFrame;
		unsigned numberOfFrames;
		unsigned frameInterval;

		void advanceFrame(Uint32);
		MultiSprite(const MultiSprite&);
		MultiSprite& operator=(const MultiSprite&);

	protected:
		float frameWidth;
		float frameHeight;
		int worldWidth;
		int worldHeight;
		int offset;
};

#endif // !__MULTISPRITE_H
